package ${package.Stereotype}.exception;

import ${package.Stereotype}.vo.ResultCode;

/**
 * 抛异常工具类
 * "https://github.com/liyupi" 程序员鱼皮
 * "https://yupi.icu" 编程导航知识星球
 */
public class ThrowUtils {

    /**
     * 条件成立则抛异常
     *
     * @param condition
     * @param runtimeException
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition
     * @param errorCode
     */
    public static void throwIf(boolean condition, ResultCode errorCode) {
        throwIf(condition, new APIException(errorCode, ""));
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition
     * @param errorCode
     * @param message
     */
    public static void throwIf(boolean condition, ResultCode errorCode, String message) {
        throwIf(condition, new APIException(errorCode, message));
    }
}
